#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define x first
#define y second

const int INF = 0x3f,MOD = 1e9+7;
template<typename T>
T pow(T b,T e,T p){
	T res = 1;
	while(e > 0){
		if(e & 1){
			res *= b;
			res %= p;
		}
		b *= b;
		b %= p;
		e >>= 1;
	}
	return res;
}
void solve(int a,int b,int p){
	
	cout << a<<"^"<<b<<" mod "<<p<<"="<<pow(a,b,p);

}
signed main()
{
	int a,b,p;
	cin >> a >> b >> p;
	solve(a,b,p);
	return 0;
}
